<template>
  <div class="form-layout">
    <!--左侧导航-->
    <div class="nav-left">
      <customAnchor :itemList="[{ name: 'box-base', title: '基础信息' }]" />
    </div>
    <!--表单区域-->
    <div class="form-right" ref="formRight">
      <customForm :data="form" :rules="propRules" ref="editForm" :disabled="propReadonly">
        <template #content>
          <div id="box-base" class="box-title">基础信息</div>
          <customFormItem label="库位名称" name="name" :parent="_self" :form="form" autoFocus/>
          <customFormItem label="库位全称" name="fullname" :parent="_self" :form="form" />
          <customFormItem
            label="库位编码"
            name="code"
            :parent="_self"
            :form="form"
            disabled
            help="自动获取"
          />
          <customFormItem
            label="默认库位"
            name="flagDefault"
            :parent="_self"
            :form="form"
            :type="constCommon.formItemType.switch.name"
          />
          <customFormItem label="库位识别码" name="idcode" :parent="_self" :form="form" help="为空时将使用库位编码" />
          <customFormItem
            label="库位类型"
            name="type"
            :parent="_self"
            :form="form"
            :type="constCommon.formItemType.selectStatic.name"
            :config="{ options: propDictionaries['type'] }"
          />
          <customFormItem
            label="上级库位"
            name="parentName"
            :parent="_self"
            :form="form"
            disabled
          />
        </template>
      </customForm>
    </div>
  </div>
</template>

<script>
import customAnchor from '@/components/custom/form/customAnchor.vue'

export default {
  data() {
    return {
      form: {},
      viewData: {},
    }
  },
  methods: {
    // 仓库选择确认
    tableDrawerWarehouseConfirm(row) {
      this.$set(this.form, 'warehouseId', row.id)
      this.$set(this.form, 'warehouseName', row.name)
    }
  },
  created() {
    this.$emit('event-register', {
      validate: (callback) => {
        return this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        this.$emit('data-callback', this.form)
        return true
      },
      afterMove: (formData) => {
        this.form = global.utils.jsonClone(formData)
        if (!this.form.id && this.propInitData) {
          this.$set(this.form, 'parentId', this.propInitData.id)
          this.$set(this.form, 'parentName', this.propInitData.label)
          this.$set(this.form, 'warehouseId', this.propInitData.meta.warehouseId)
          this.$set(this.form, 'warehouseName', this.propInitData.meta.warehouseName)
          this.$set(this.form, 'flagDefault', false)
          this.$set(this.form, 'code', '自动获取')
        }
      },
      afterSave: () => {},
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {},
      beforeFlow: (flowButtonKey) => {
        return true
      },
      afterFlow: (flowButtonKey) => {},
      beforeClose: () => {
        return true
      },
    })
  },
  props: {
    propParent: Object,
    propInitData: Object,
    propPrimaryKey: String,
    propDictionaries: Object,
    propCurrentRow: Object,
    propViewFormData: Object,
    propReadonly: Boolean,
    propStatus: String,
    propRules: Object,
  },
  components: {customAnchor},
  computed: {},
}
</script>
